package list;
//List集合特点:有序,可重复,有索引

//List集合特有方法
/*
        void add(int index,E element) 在此集合中的指定位置插入指定的元素
        E remove(int index) 删除指定索引处的元素，返回被删除的元素
        E set集合(int index,E element) 修改指定索引处的元素，返回被修改的元素
        E get(int index) 返回指定索引处的元素

 */

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Demo02 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("100");
        list.add("200");
        list.add("300");

        list.add(1, "1000");
        list.remove(1);
        list.set(0,"1000");
        list.set(1,"2000");
        list.set(2,"3000");


        System.out.println(list);
        System.out.println("~~~~~~~~~~");
        //迭代器遍历
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            System.out.println(it.next());
        }
        System.out.println("~~~~~~~~~~");
        //普通for循环
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }
        System.out.println("~~~~~~~~~~");
        //增强for循环
        for (String s : list) {
            System.out.println(s);
        }
        System.out.println("~~~~~~~~~~");
    }
}

